<template>
	<view class="header-bg-image header-bg">
		<view style="height: 50rpx;"></view>
		<view class="padding-30">
			<view class="margin-30-0 flex-around" @click="$tools.navigateBack()">
				<u-icon name="arrow-left" color="#333333" size="20"></u-icon>
				<view class="fontSize-18 color-000 flex1 text-center">折扣卷</view>
				<view style="width: 40rpx;"></view>
			</view>
			<view class="margin-30-0">
				<u-tabs :list="list1" lineColor="#967C5E" @click="chooseTabs"></u-tabs>
			</view>
			<!-- 列表 -->
			<view class="bg-fff border-radius20 padding-30 margin-bottom30"
			v-for="(item,index) in list" :key="index" 
			@click="$tools.navigateTo('/pages/index/score-list/discount-pay-success?coupons_id='+item.id)">
				<view class="flex-between margin-bottom20">
					<view class="flex-alignItems-center">
						<view class="fontSize-15 color-000 margin-right10">{{item.store_title}}</view>
						<u-icon name="arrow-right" color="#333333" size="16"></u-icon>
					</view>
					<view class="fontSize-15 color-FE3232">{{item.status_text}}</view>
				</view>
				<view class="flex-between">
					<image class="img-160 border-radius10" :src="item.goods.image" mode=""></image>
					<view class="flex1 margin-left20">
						<view class="fontSize-15 color-000 margin-bottom20">{{item.goods.title}}</view>
						<view class="fontSize-13 color-999 margin-bottom20">{{item.start_time}} 至 {{item.end_time}}</view>
						<view style="color: #C90F0F;" class="margin-bottom10">
							<text class="fontSize-15">￥</text>
							<text style="font-size: 20px;">{{item.goods.price}}</text>
						</view>
					</view>
				</view>
			</view>
			
			<u-empty v-if="list.length == 0"
			        mode="list"
			        icon="http://cdn.uviewui.com/uview/empty/list.png"
					width="150px"
					height="150px"
					text="列表为空"
					textSize="18"
			>
			</u-empty>
			<view style="padding-bottom: 100rpx;">
				<u-loadmore v-if="loading" status="loading" />
				<u-loadmore v-if="isLastPage" status="nomore" />
			</view>
			
		</view>
	</view>
</template>

<script>
	export default {
		data(){
			return{
				list1:[
					{name:'待使用',status:0},
					{name:'已使用',status:1}
				],
				status:0,
				page: 1,
				limit: 10,
				list: [],
				isLastPage: false,
				loading: false,
			}
		},
		onShow() {
			this.page = 1
			this.limit = 10
			this.list = []
			this.getScoreList()
		},
		// 刷新 上拉刷新
		onPullDownRefresh() {
			this.page = 1
			this.isLastPage = false
			this.list = []
			this.getScoreList().finally(() => {
				// 停止当前页面下拉刷新
				uni.stopPullDownRefresh();
			});
		},
		// 加载下一页 下拉加载
		onReachBottom() {
			if (this.list.length >= this.page * this.limit) {
				this.isLastPage = false;
				this.page += 1;
				this.getScoreList();
			} else {
				this.isLastPage = true
			}
		},
		methods:{
			chooseTabs(e) {
				this.list1Name = e.name
				this.status = e.status
				this.page = 1
				this.limit = 10
				this.list = []
				this.getScoreList()
			},
			// 列表
			async getScoreList() {
				this.$http.post(this.$api.coupon_list, {
					page: this.page,
					limit: this.limit,
					status:this.status
				}, {
					token: true
				}).then(res => {
					this.list = [...this.list, ...res.data]
				}).finally(() => {
					// 停止当前页面下拉刷新
					uni.stopPullDownRefresh();
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
</style>